file_test_runner
File-based test runner for running tests found in files via cargo test
.
This does two main steps:
- Collects all files from a specified directory using a provided strategy
(
file_test_runner::collect_tests
). - Runs all the files as tests with a custom test runner
(
file_test_runner::run_tests
).
The files it collects may be in any format. It's up to you to decide how they should be structured.
Examples
- https://github.com/denoland/deno_doc/blob/main/tests/specs_test.rs
- https://github.com/denoland/deno_graph/blob/main/tests/specs_test.rs
- https://github.com/denoland/deno/tree/main/tests/specs
Setup
-
Add a
[[test]]
section to your Cargo.toml:[[]] = "specs" = "tests/spec_test.rs" = false
-
Add a
tests/spec_test.rs
file to run the tests with a main function:use collect_and_run_tests; use CollectedTest; use CollectOptions; use TestPerFileCollectionStrategy; use RunOptions; use TestResult; // The `test` object only contains the test name and // the path to the file on the file system which you can // then use to determine how to run your test
-
Add some files to the
tests/specs
directory or within sub directories of that directory. -
Run
cargo test
to run the tests. Filtering should work OOTB.